from django.shortcuts import render_to_response
from t8.user.models import userModel
import md5
from t8.user.userForm import loginForm

def login(request):
    if request.method == 'POST':
        form = loginForm(request.POST)
        if form.is_valid():
            try :
                user = userModel.objects.get(name=request.POST.get('name'))
                if md5.new(request.POST.get('password')).hexdigest() == user.password :
                    return render_to_response('base.html', {'form': form})
                else:
                    form.passwordIsWrong = 'Y'
            except :
                form.userNotExist = 'Y'
    else:
        form = loginForm()
    return render_to_response('login.html', {'form': form})
            
def development(request):
    return render_to_response('base.html')
